package com.marvels.financial.collection.controller;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.marvels.common.dto.MarvelsResultDTO;
import com.marvels.common.exception.MarvelsBusinessException;
import com.marvels.common.exception.MarvelsErrorCode;
import com.marvels.common.utils.MarvelsLogUtil;
import com.marvels.financial.collection.dto.CollectStatisticalParamDTO;
import com.marvels.financial.collection.dto.CollectStatisticalResultDTO;
import com.marvels.financial.collection.service.CollectStatisticalService;


/**
 * 催收统计
 * @author 吴俊峰
 */
@RequestMapping("financial/collection/statistical/service")
@RestController
public class CollectStatisticalController {
	
	@Autowired
	private CollectStatisticalService collectStatisticalService;
	
	@InitBinder
	public void initBinder(WebDataBinder binder) {
		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
		dateFormat.setLenient(false);
		binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));
	}
	
	/**
	 * 查询催收统计列表
	 * @return
	 */
	@RequestMapping("queryList")
	@ResponseBody
	public MarvelsResultDTO collectCondition(@RequestBody CollectStatisticalParamDTO dto){
		try {
			List<CollectStatisticalResultDTO> list = collectStatisticalService.queryList(dto);
			MarvelsLogUtil.getInstance().info("查询催收统计列表返回结果=======》》》" + list);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(),MarvelsErrorCode.SUCCESS.getDesc(), list);
		} catch (MarvelsBusinessException e) {
			MarvelsLogUtil.getInstance().error(">>>>>>>>>查询催收统计列表FAIL:", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.FAIL.getValue(), e.getMessage(), null);
		}catch (Exception e) {
			MarvelsLogUtil.getInstance().error(">>>>>>>>>查询催收统计列表异常", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(), "查询催收统计列表异常", null);
		}
	}
	
}
